package br.com.uniban.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

public class SendMail {


	private static final String EMAIL_KEY="email";
	private static final String SENHA_KEY="senha";
	private static final String HOST_KEY="host";
	private static final String TITULO_KEY = "titulo";
	private static final String ARQUIVO = "email.properties";
	
	public void sendMail(String from,String to, String subject, String message) {
		HtmlEmail email = new HtmlEmail(); 
		try {  
			
	        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(ARQUIVO);
	    	Properties properties = new Properties();
	    	properties.load(inputStream);
			
	        email.setDebug(false);  
	        email.setHostName(properties.getProperty(HOST_KEY)); 
	        email.setAuthentication(properties.getProperty(EMAIL_KEY),properties.getProperty(SENHA_KEY));  
	        email.setSmtpPort(465);  
	        email.addTo(to);
	        email.setFrom(from,properties.getProperty(TITULO_KEY)); 
	        email.setSubject(subject);  
	        email.setHtmlMsg(message);  
	        email.setSSL(true);   
	        email.send();  
	  
	        } catch (EmailException e) {  	  
	        	System.out.println(e.getMessage());  
	  
	        } catch (IOException e) {
	        	System.out.println(e.getMessage());
		}
	}
}
